package com.hqyj.mybatisplusdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.hqyj.mybatisplusdemo.model.Db1;
import com.hqyj.mybatisplusdemo.dao.Db1Dao;
import com.hqyj.mybatisplusdemo.service.Db1Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 
 * @since 2024-10-20
 */
@Service
public class Db1ServiceImpl extends ServiceImpl<Db1Dao, Db1> implements Db1Service {

    //如果参数 createname == null || createname == '' ，不带这个条件，否则带
    //select * from db1 <where><if>.... sql ....</if></where>
    @Override
    public List<Db1> selectByConditionWrapper(String createname) {

        QueryWrapper<Db1> wrapper = new QueryWrapper<Db1>();
        wrapper.like(StringUtils.isNotBlank(createname),"createname", createname);
        List<Db1> list = baseMapper.selectList(wrapper);

        return list;
    }

    public List selectByWrapper2(String createname, int minid, int maxid) {
        QueryWrapper<Db1> queryWrapper = new QueryWrapper<Db1>();
        queryWrapper.like("createname", createname).between("createid", minid, maxid).isNotNull("createid");
        List<Db1> list = baseMapper.selectList(queryWrapper);
        return list;
    }

    public List selectByWrapper3(String createname, int minid, int maxid) {
        QueryWrapper<Db1> queryWrapper = new QueryWrapper<Db1>();
        queryWrapper.like("createname", createname).or().between("createid", minid, maxid).isNotNull("createid");
        List<Db1> list = baseMapper.selectList(queryWrapper);
        return list;
    }


}
